<?php
/**
 * Created by PhpStorm.
 * User: Admin
 * Date: 2018/7/23
 * Time: 12:20
 */
namespace app\common\model;

use think\Model;

class Work extends Model
{
    protected $name='work';

    protected $autoWriteTimestamp='int';

    protected $createTime='ctime';

    protected $updateTime='utime';

    protected $dateFormat='Y-m-d H:i';

    protected $append=['category_text','pcategory_text','part_words'];

    public function getCategoryTextAttr($value,$data)
    {
        return (string)db('Category')->where('id',$data['cid'])->value('name');
    }

    public function getPcategoryTextAttr($value,$data)
    {
        return (string)db('Category')->where('id',$data['pid'])->value('name');
    }

    public function getPartWordsAttr($value,$data)
    {
        return db('work_words')->where('pid',$data['id'])->column('words');
    }
}